# 使用 Alpine 官方 Python 镜像
FROM python:3.12-alpine

# 设置工作目录
WORKDIR /app

# 设置时区为亚洲/上海
ENV TZ=Asia/Shanghai

# 替换 Alpine 默认源为阿里云源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update

# 安装必要的依赖
RUN apk add --no-cache --virtual .build-deps \
    gcc \
    musl-dev \
    python3-dev \
    libffi-dev \
    openssl-dev \
    cargo \
    && apk add --no-cache \
    tzdata \
    openssl \
    mariadb-connector-c-dev

# 复制并安装 Python 依赖
COPY requirements.txt .
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip install --no-cache-dir -r requirements.txt && \
    rm -rf ~/.cache/pip && \
    apk del .build-deps

# 复制应用代码
COPY . .

# 启动命令
CMD ["python", "app.py"]